import type { SopAppVersion } from "@/pages/tool/appVersion/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //版本号
  version?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: SopAppVersion[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/tool/sop/version/pageList",
    data
});
const getInfo = (id: React.Key): Promise<SopAppVersion> =>
  apiClient.get({
    url: `/tool/sop/version/${id}`
});

const add = (data: SopAppVersion): Promise<SopAppVersion> =>
  apiClient.post({
    url: "/tool/sop/version",
    data
});

const update = (data: SopAppVersion): Promise<SopAppVersion> =>
  apiClient.put({
    url: "/tool/sop/version",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/tool/sop/version",
    params: {
    ids: ids.join(",")
  }
});

//下载文件
const downloadFile = (appId: React.Key) => {
  apiClient.get<any>({ url: `/tool/sop/version/download/${appId}` });
};

// 根据路径删除文件
const deleteFile = (filePath: string) => {
  apiClient.delete({
    url: `/tool/sop/version/file`,
    params: {
      filePath
    }
  });
};

export const sopAppVersionService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  downloadFile,
  deleteFile
};

export default sopAppVersionService;